using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Runtime.Serialization;
using System.Security.Permissions;

using CureConsulting;
using CureConsulting.Common;

namespace Blog.Net.Common.DataObjects
{
	[Serializable]
	public partial class Login : DataObjectBase
	{
		#region Constructors

		/// <summary>
		/// Create a Login object Empty Constructor
		/// </summary>
		public Login() { }

		/// <summary>
		/// Create a Login object Full Constructor
		/// </summary>
		/// <param name="Active"></param>
		/// <param name="Email"></param>
		/// <param name="FirstName"></param>
		/// <param name="LastName"></param>
		/// <param name="UserName"></param>
		/// <param name="Password"></param>
		/// <param name="PasswordQuestion"></param>
		/// <param name="PasswordAnswer"></param>
		public Login( bool Active, string Email, string FirstName, string LastName, string UserName, string Password, string PasswordQuestion, string PasswordAnswer ) : this()
		{
			this.Active = Active;
			this.Email = Email;
			this.FirstName = FirstName;
			this.LastName = LastName;
			this.UserName = UserName;
			this.Password = Password;
			this.PasswordQuestion = PasswordQuestion;
			this.PasswordAnswer = PasswordAnswer;
		}
		/// <summary>
		/// Create a Login object from serialization
		/// </summary>
		protected Login(SerializationInfo info, StreamingContext context) : base(info, context)
      	{
			_active = (bool)info.GetValue("_active", typeof(bool));
			_email = (string)info.GetValue("_email", typeof(string));
			_firstName = (string)info.GetValue("_firstName", typeof(string));
			_lastName = (string)info.GetValue("_lastName", typeof(string));
			_userName = (string)info.GetValue("_userName", typeof(string));
			_password = (string)info.GetValue("_password", typeof(string));
			_passwordQuestion = (string)info.GetValue("_passwordQuestion", typeof(string));
			_passwordAnswer = (string)info.GetValue("_passwordAnswer", typeof(string));
			_roles = (IList<Role>)info.GetValue("_roles", typeof(IList<Role>));
      	}
		#endregion
		
		#region Member Variables
		
		protected bool _active;
		protected string _email;
		protected string _firstName;
		protected string _lastName;
		protected string _userName;
		protected string _password;
		protected string _passwordQuestion;
		protected string _passwordAnswer;
		protected IList<Role> _roles;

		#endregion

		#region Public Properties
		
		/// <summary>
		/// Login Active
		/// </summary>
		public virtual bool Active
		{
			get { return _active; }
			set 
			{
				UpdateState(_active , value);
				_active = value;
			}
		}

		/// <summary>
		/// Login Email
		/// </summary>
		public virtual string Email
		{
			get { return _email; }
			set
			{
				if (value != null && value.Length > 255)
					throw new ArgumentOutOfRangeException("Invalid value for Email", value, value.ToString());
				UpdateState(_email , value);
				_email = value;
			}
		}

		/// <summary>
		/// Login FirstName
		/// </summary>
		public virtual string FirstName
		{
			get { return _firstName; }
			set
			{
				if (value != null && value.Length > 255)
					throw new ArgumentOutOfRangeException("Invalid value for FirstName", value, value.ToString());
				UpdateState(_firstName , value);
				_firstName = value;
			}
		}

		/// <summary>
		/// Login LastName
		/// </summary>
		public virtual string LastName
		{
			get { return _lastName; }
			set
			{
				if (value != null && value.Length > 255)
					throw new ArgumentOutOfRangeException("Invalid value for LastName", value, value.ToString());
				UpdateState(_lastName , value);
				_lastName = value;
			}
		}

		/// <summary>
		/// Login UserName
		/// </summary>
		public virtual string UserName
		{
			get { return _userName; }
			set
			{
				if (value != null && value.Length > 255)
					throw new ArgumentOutOfRangeException("Invalid value for UserName", value, value.ToString());
				UpdateState(_userName , value);
				_userName = value;
			}
		}

		/// <summary>
		/// Login Password
		/// </summary>
		public virtual string Password
		{
			get { return _password; }
			set
			{
				if (value != null && value.Length > 255)
					throw new ArgumentOutOfRangeException("Invalid value for Password", value, value.ToString());
				UpdateState(_password , value);
				_password = value;
			}
		}

		/// <summary>
		/// Login PasswordQuestion
		/// </summary>
		public virtual string PasswordQuestion
		{
			get { return _passwordQuestion; }
			set
			{
				if (value != null && value.Length > 255)
					throw new ArgumentOutOfRangeException("Invalid value for PasswordQuestion", value, value.ToString());
				UpdateState(_passwordQuestion , value);
				_passwordQuestion = value;
			}
		}

		/// <summary>
		/// Login PasswordAnswer
		/// </summary>
		public virtual string PasswordAnswer
		{
			get { return _passwordAnswer; }
			set
			{
				if (value != null && value.Length > 255)
					throw new ArgumentOutOfRangeException("Invalid value for PasswordAnswer", value, value.ToString());
				UpdateState(_passwordAnswer , value);
				_passwordAnswer = value;
			}
		}

		/// <summary>
		/// Login Roles
		/// </summary>
		public virtual IList<Role> Roles
		{
			get
			{
				if (_roles==null)
				{
					_roles = new SortableBindingList<Role>();
				}
				return _roles;
			}
			set { _roles = value; }
		}

		
		#endregion
		
		#region Methods
		/// <summary>
        /// Set object data for serialization
        /// </summary>
        /// <param name="info"></param>
        /// <param name="context"></param>
      	[SecurityPermissionAttribute(SecurityAction.Demand, SerializationFormatter = true)]
		public override void GetObjectData(SerializationInfo info, StreamingContext context)
      	{
			info.AddValue("_active", _active);
			info.AddValue("_email", _email);
			info.AddValue("_firstName", _firstName);
			info.AddValue("_lastName", _lastName);
			info.AddValue("_userName", _userName);
			info.AddValue("_password", _password);
			info.AddValue("_passwordQuestion", _passwordQuestion);
			info.AddValue("_passwordAnswer", _passwordAnswer);
			info.AddValue("_roles", _roles);			
         	base.GetObjectData(info, context);
      	}
		#endregion
	}
}